<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
namespace core;
defined('BY_JYA') or exit('error');
class menus{
	//添加操作员
	public $operator_types=array(1,2,4);
	public function get_sysmenus($uid=0,$isinfo=false){
		global $_AR;
		$uid=$uid?:$_SESSION['uid'];
		if($_SESSION['user']['type']==3){
			$menusinfo=pdo_get('core_account_group',array('id'=>$_SESSION['account']['groupid']),array('menus','othermenus'));
		}elseif($_SESSION['user']['type']==1 || $_SESSION['user']['type']==2 || $_SESSION['user']['type']==4){
			$menusinfo=pdo_get('core_user_permissions',array('uniacid'=>$_SESSION['uniacid'],'uid'=>$uid),array('menus','othermenus'));
		}
		$othermenus=$menusinfo['othermenus']?json_decode($menusinfo['othermenus'],true):array();
		$menus=$menusinfo['menus'];
		if($menus){
			$framess=json_decode($menus,true);
		}else{
			$framess=core_setting('menu');
		}
		if(!$_AR['page']['plugin_menu']){
			//如果没有关闭扩展功能显示，则读取扩展功能菜单
			$childs=get_plugin_intypes();
			$demointypes=get_plugin_intypes(true);
			foreach($childs as $k=>&$child){
				$child=array('title'=>$child?:$demointypes[$k],'child'=>array());
			}
			$plugin_menu=array(
				'title'=>'我的场景_Industry app',
				'url'=>array('plugin'=>'core','action'=>'home.plugin_home','op'=>'get','query'=>'nolegao=0','title'=>'场景应用_Industry app'),
				'fa'=>'icon-yingyongbao',
				'legao_app'=>1,
				'child'=>$childs,
			);
			$plugins=pdo_getall('core_plugins',array('hide'=>0,'is_legao'=>1),array('name','title','style','intype'),'','star desc,paixu desc,id desc');
			foreach($plugins as $row){
				$plugin_menu['child'][$row['intype']]['child'][]=array('url'=>array('plugin'=>$row['name'],'action'=>'basic.module_home'),'title'=>$row['title']);
			}
			$plugin_menu['child']=array_values($plugin_menu['child']);
			$legao_app=$plugin_menu;
			if(!$othermenus[0]['hide']){
				$framess[]=$plugin_menu;
			}
			//其他应用
			//兼容插件
			if($access['ismodule']==1){
				$api_modulemenus=model('core/template')->get_modulemenus($access['plugin']);
				if($api_modulemenus){
					$childs=$api_modulemenus;
				}
			}
			if(!$api_modulemenus){
				$childs=get_plugin_styles();
				foreach($childs as &$child){
					$child=array('title'=>$child,'child'=>array());
				}
				$childs['7']=array('title'=>'其他应用','child'=>array());
			}
			$plugin_menu=array(
				'title'=>'我的应用_Other app',
				'url'=>array('plugin'=>'core','action'=>'home.plugin_home','op'=>'other','query'=>'nolegao=1','title'=>'其他应用_Other app'),
				'fa'=>'icon-similarproduct',
				'other_app'=>1,
				'child'=>$childs,
			);
			if(!$api_modulemenus){
				$plugins=pdo_getall('core_plugins',array('hide'=>0,'is_legao'=>0),array('name','title','style'),'','star desc,paixu desc,id desc');
				foreach($plugins as $row){
					if(!$row['style'] || $row['style']>6){
						$row['style']=7;
					}
					$plugin_menu['child'][$row['style']]['child'][]=array('url'=>array('plugin'=>$row['name'],'action'=>'basic.module_home'),'title'=>$row['title']);
				}
			}
			$plugin_menu['child']=array_values($plugin_menu['child']);
			$other_app=$plugin_menu;
			if(!$othermenus[1]['hide']){
				$framess[]=$plugin_menu;
			}
		}
		
		//整理菜单，删掉无权访问按钮，和隐藏的按钮。注意：系统菜单按钮和系统权限集并非完全一致。因此需要调用权限判断函数判断权限
		foreach($framess as $key1=>&$menu){
			if($menu['url']['plugin']=='core' && $menu['url']['action']=='basic.welcome' && strpos($_SESSION['account']['noshow_mainmenus'],';siteapp;') !== false){
				unset($framess[$key1]);
				continue;
			}
			if($menu['url']['plugin']=='core' && $menu['url']['action']=='basic.xiu_data' && strpos($_SESSION['account']['noshow_mainmenus'],';sitexiu;') !== false){
				unset($framess[$key1]);
				continue;
			}
			if($menu['url']['plugin']=='jy_weishop' && $menu['url']['action']=='basic.module_home' && strpos($_SESSION['account']['noshow_mainmenus'],';siteshop;') !== false){
				unset($framess[$key1]);
				continue;
			}
			if($menu['url']['plugin']=='core' && $menu['url']['action']=='wxwork.welcome' && strpos($_SESSION['account']['noshow_mainmenus'],';sitework;') !== false){
				unset($framess[$key1]);
				continue;
			}
			if($menu['hide']){
				unset($framess[$key1]);
				continue;
			}
			foreach($menu['child'] as $key2=>&$sub){
				if($sub['hide']){
					unset($menu['child'][$key2]);
					continue;
				}
				if($sub['title']=='小程序_wxapp' && strpos($_SESSION['account']['noshow_app'],';wxapp;') !== false){
					unset($menu['child'][$key2]);
					
					continue;
				}
				if($sub['title']=='微官网_h5web' && strpos($_SESSION['account']['noshow_app'],';mobile;') !== false){
					unset($menu['child'][$key2]);
					continue;
				}
				if($sub['title']=='PC站_PC' && strpos($_SESSION['account']['noshow_app'],';pc;') !== false){
					unset($menu['child'][$key2]);
					continue;
				}
				if(strpos($sub['title'],'APP打包')!== false && strpos($_SESSION['account']['noshow_app'],';pc;') !== false){
					unset($menu['child'][$key2]);
					continue;
				}
				foreach($sub['child'] as $key3=>&$row){
					if($row['hide']){
						unset($sub['child'][$key3]);
						continue;
					}
					if(is_array($row['url']) && !check_permission($row['url']['plugin'],$row['url']['action'],$row['url']['op'])){
						unset($sub['child'][$key3]);
						continue;
					}
					$menu['url2']=$menu['url2']?:$row['url'];
				}
				if(!$sub['child']){
					unset($menu['child'][$key2]);
				}
			}
			$check1=check_permission($menu['url']['plugin'],$menu['url']['action'],$menu['url']['op']);
			if(!$menu['child'] && (!$menu['url'] || !$check1)){
				unset($framess[$key1]);
			}elseif(!$check1 && $menu['url']){
				$menu['url']=$menu['url2'];
			}
		}
		$framess=array_values($framess);
		if($isinfo){
			$res=array(
				'framess'=>$framess,
				'legao_app'=>$legao_app,
				'other_app'=>$other_app,
			);
			return $res;
		}else{
			return $framess;
		}
	}
	public function get_sitemenus($pluginname='',$type=0){
		$menus=array(
		'title'=>'站点设置','fa'=>'icon-listzuhe','url'=>'core/setting.site/','child'=>array(
			array('title'=>'站点信息','child'=>array(
				array('url'=>'core/setting.site/','title'=>'站点设置'),
				array('url'=>'core/account.siteinfo/','title'=>'站点信息'),
				array('url'=>'core/account.fujian/','title'=>'附件管理'),
				array('url'=>'core/account.user/','title'=>'站点密码'),
				array('url'=>'core/account.recharge/','title'=>'账户充值'),
				array('url'=>'core/account.credit_log/','title'=>'账户余额日志'),
				array('url'=>'core/account.pay_log/','title'=>'账户支付日志'),
				array('url'=>'core/account.renzheng/','title'=>'认证文件上传'),
				array('url'=>'core/account.develop/','title'=>'多平台转接'),
				array('url'=>'core/account.open_fans/','title'=>'粉丝互通'),
				array('url'=>'core/account.api_data/','title'=>'云接口参数'),
				array('url'=>'core/setting.wxapp/','title'=>'站点小程序'),
			)),
			array('title'=>'参数设置','child'=>array(
				array('url'=>'core/setting.sms/','title'=>'短信接口设置'),
				array('url'=>'core/setting.pay/','title'=>'支付参数设置'),
				array('url'=>'core/setting.domain_set/','title'=>'站点域名设置'),
				array('url'=>'core/setting.registerset/','title'=>'站点注册设置'),
				array('url'=>'core/setting.mail/','title'=>'邮件参数册设置'),
				array('url'=>'core/setting.cash/','title'=>'提现设置'),
				array('url'=>'core/setting.fans/','title'=>'粉丝信息获取'),
				array('url'=>'core/setting.attachment/','title'=>'附件存储设置'),
				array('url'=>'core/setting.msgset/list/plugin_name='.$pluginname,'title'=>'消息开启设置'),
				array('url'=>'core/setting.msgtpl/list/plugin_name='.$pluginname,'title'=>'微信模板库'),
				array('url'=>'core/setting.sms_temp/','title'=>'短信消息库'),
			)),
			array('title'=>'公众号','child'=>array(
				array('url'=>'core/wechat.list/','title'=>'公众号管理'),
				array('url'=>'core/wechat.back/','title'=>'消息回复管理'),
				array('url'=>'core/wechat.menu/','title'=>'消息群发'),
				array('url'=>'core/wechat.media/','title'=>'素材管理'),
				array('url'=>'core/wechat.fans/','title'=>'粉丝管理'),
				array('url'=>'core/wechat.fansgroup/','title'=>'粉丝分组'),
				array('url'=>'core/wechat.specal_back/follow_back','title'=>'关注回复设置'),
				array('url'=>'core/wechat.specal_back/default_back/','title'=>'默认回复设置'),
				array('url'=>'core/wechat.qr/','title'=>'二维码管理'),
				array('url'=>'core/wechat.specal_back/default_back/','title'=>'默认回复设置'),
			)),
			array('title'=>'小程序','child'=>array(
				array('url'=>'core/wxapp.list/get/','title'=>'DIY小程序'),
				array('url'=>'core/wxapp.plugin/','title'=>'应用小程序'),
				array('url'=>'core/wxapp.list/dabaolist/type=7','title'=>'H5小程序'),
				array('url'=>'core/wxapp.authlist/','title'=>'一键申请小程序'),
				array('url'=>'core/wxapp.home/','title'=>'小程序模板'),
				array('url'=>'core/wxapp.fans/','title'=>'小程序粉丝'),
				array('url'=>'core/wxapp.up_list/','title'=>'上传任务列表'),
				array('url'=>'core/wxapp.jump/','title'=>'小程序跳转'),
			)),
			array('title'=>'微官网','child'=>array(
				array('url'=>'core/website.mobile_web/','title'=>'微官网列表'),
				array('url'=>'core/website.mobile_template/','title'=>'微官网模板'),
				array('url'=>'core/website.group/','title'=>'微官网分组'),
			)),
			array('title'=>'站点会员','child'=>array(
				array('url'=>'core/member.member/','title'=>'会员列表'),
				array('url'=>'core/member.group/','title'=>'会员等级'),
				array('url'=>'core/member.setting/','title'=>'参数设置'),
				array('url'=>'core/member.wxcard/','title'=>'微信会员卡'),
				array('url'=>'core/member.tixian/','title'=>'会员提现'),
				array('url'=>'core/member.red_pack/list','title'=>'会员红包'),
				array('url'=>'core/member.red_pack/outlog','title'=>'红包提现申请'),
				array('url'=>'core/member.paylog/','title'=>'支付记录'),
				array('url'=>'core/member.creditlog/','title'=>'积分余额记录'),
				array('url'=>'core/member.recharge_log/','title'=>'充值记录'),
				array('url'=>'core/member.qiandao/','title'=>'签到记录'),
				array('url'=>'core/member.reward/','title'=>'奖品管理'),
				array('url'=>'core/member.reward_log/','title'=>'领奖记录'),
			)),
			array('title'=>'微宣传','child'=>array(
				array('url'=>'core/basic.xiu_form/','title'=>'宣传单页'),
				array('url'=>'core/basic.seo_home/','title'=>'多媒体宣传'),
				array('url'=>'core/account.message/','title'=>'留言/表单'),
				array('url'=>'core/account.article_list/','title'=>'文章列表'),
				array('url'=>'core/account.article_fenlei/','title'=>'文章分类'),
				array('url'=>'jy_weishop/video.index/','title'=>'视频列表'),
				array('url'=>'jy_weishop/video.groups/','title'=>'视频分类'),
				array('url'=>'core/account.content/','title'=>'内容云'),
				array('url'=>'core/account.content_group/','title'=>'内容云分类'),
				array('url'=>'jy_poster/list/','title'=>'宣传海报'),
			)),
			array('title'=>'操作权限','child'=>array(
				array('url'=>'core/account.operator/','title'=>'站点操作员'),
				array('url'=>'core/basic.plugin_perm//plugin_name='.$pluginname,'title'=>'应用操作权限'),
			)),
		));
		return $menus;
	}
}